//
//  SaoMiaoJieGuoViewController.m
//  fff
//
//  Created by 张利强 on 2016/11/10.
//  Copyright © 2016年 hbyj. All rights reserved.
//

#import "SaoMiaoJieGuoViewController.h"

@interface SaoMiaoJieGuoViewController ()
@property (weak, nonatomic) IBOutlet UILabel *labelName;

/**webview*/
@property (nonatomic, strong) UIWebView *webview;

@end

@implementation SaoMiaoJieGuoViewController

- (void)viewWillAppear:(BOOL)animated{
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav_background"] forBarMetrics:UIBarMetricsDefault];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    self.navigationController.navigationBar.tintColor = [UIColor grayColor];
    self.navigationItem.title = @"扫描结果";
    //[self.navigationController.navigationBar addSubview:_progressView];
}

- (void)viewDidDisappear:(BOOL)animated{
    //[_progressView removeFromSuperview];
    [self.delegate startAni];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (self.isURL) {
        [self.labelName removeFromSuperview];
        [self initUI];
    }else{
        self.labelName.text = self.valueForPage;
        self.labelName.font = [UIFont systemFontOfSize:20 weight:1];
    }
}

- (void)initUI{
    //_progressProxy = [[NJKWebViewProgress alloc] init];
    _webview = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
    [self.view addSubview:_webview];
    //_webview.delegate = _progressProxy;
    //_progressProxy.webViewProxyDelegate = self;
    //_progressProxy.progressDelegate = self;
    
    CGFloat progressBarHeight = 2.f;
    CGRect navigationBarBounds = self.navigationController.navigationBar.bounds;
    CGRect barFrame = CGRectMake(0, navigationBarBounds.size.height, navigationBarBounds.size.width, progressBarHeight);
    //_progressView = [[NJKWebViewProgressView alloc] initWithFrame:barFrame];
    //_progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
    [self loadGoogle];
}

- (void)loadGoogle
{
    //    self.valueForPage = [self.valueForPage stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    //    NSString *charactersToEscape = @"?!@#$^&%*+,:;='\"`<>()[]{}/\\| ";
    //    NSCharacterSet *allowedCharacters = [[NSCharacterSet characterSetWithCharactersInString:charactersToEscape] invertedSet];
    //    NSString *encodedUrl = [self.valueForPage stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacters];
    
    //    self.valueForPage = [self.valueForPage stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet controlCharacterSet]];
    //    NSLog(@"%@",encodedUrl);
    
    NSURLRequest *req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:self.valueForPage]];
    [_webview loadRequest:req];
}

@end
